package com.ruoyi.car.business.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.github.pagehelper.PageHelper;
import com.ruoyi.car.business.domain.BusStatement;
import com.ruoyi.car.business.mapper.BusStatementMapper;
import com.ruoyi.car.business.query.StatementQuery;
import com.ruoyi.car.business.service.IBusStatementService;
import com.ruoyi.common.core.page.TablePageInfo;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 结算单Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-01-27
 */
@Service
@Transactional
public class BusStatementServiceImpl implements IBusStatementService
{
    @Autowired
    private BusStatementMapper busStatementMapper;

    @Override
    public TablePageInfo<BusStatement> query(StatementQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<BusStatement>(busStatementMapper.selectForList(qo));
    }

    @Override
    public void updateAmount(Long statementId, BigDecimal totalAmount, BigDecimal totalQuantity, BigDecimal disCountPrice) {
        busStatementMapper.updateAmount(statementId,totalAmount,totalQuantity,disCountPrice);
    }

    /**
     * 查询结算单
     * 
     * @param id 结算单主键
     * @return 结算单
     */
    @Override
    public BusStatement selectBusStatementById(Long id)
    {
        return busStatementMapper.selectBusStatementById(id);
    }

    /**
     * 查询结算单列表
     * 
     * @param busStatement 结算单
     * @return 结算单
     */
    @Override
    public List<BusStatement> selectBusStatementList(BusStatement busStatement)
    {
        return busStatementMapper.selectBusStatementList(busStatement);
    }

    /**
     * 新增结算单
     * 
     * @param busStatement 结算单
     * @return 结果
     */
    @Override
    public int insertBusStatement(BusStatement busStatement)
    {
        busStatement.setCreateTime(DateUtils.getNowDate());
        return busStatementMapper.insertBusStatement(busStatement);
    }

    /**
     * 修改结算单
     * 
     * @param busStatement 结算单
     * @return 结果
     */
    @Override
    public int updateBusStatement(BusStatement busStatement)
    {
        return busStatementMapper.updateBusStatement(busStatement);
    }

    /**
     * 批量删除结算单
     * 
     * @param ids 需要删除的结算单主键
     * @return 结果
     */
    @Override
    public int deleteBusStatementByIds(String ids)
    {
        return busStatementMapper.deleteBusStatementByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除结算单信息
     * 
     * @param id 结算单主键
     * @return 结果
     */
    @Override
    public int deleteBusStatementById(Long id)
    {
        return busStatementMapper.deleteBusStatementById(id);
    }

    @Override
    public void pay(Long statementId, Long userId, Integer status) {
        busStatementMapper.pay(statementId,userId,status);
    }

    @Override
    public BusStatement getByAppointmentId(Long appointmentId) {
        return busStatementMapper.getByAppointmentId(appointmentId);
    }

    @Override
    public void saveForAppointment(BusStatement statement) {
        busStatementMapper.insertBusStatement(statement);
    }
}
